package com.infotech.NginxMonitor.service;

import java.util.Timer;

import com.infotech.NginxMonitor.common.StaticValue;

public class DataRefresh {
	private static boolean isRunning = StaticValue.NO;

	public static synchronized boolean getIsRunning() {
		return DataRefresh.isRunning;
	}

	public static synchronized void setIsRunning(boolean isRunning) {
		DataRefresh.isRunning = isRunning;
	}

	public void startup() {
		if (!isRunning) {
			DataRefresh.setIsRunning(StaticValue.YES);
			SystemDataMonitor.timer = new Timer();
			SystemDataMonitor.timer.schedule(new SystemDataMonitor(), 0, 1000);
			
			ServerDataMonitor.timer = new Timer();
			ServerDataMonitor.timer.schedule(new ServerDataMonitor(), 0, 1000);
		}
	}
	
	public void shutdown(){
		SystemDataMonitor.timer.cancel();
		ServerDataMonitor.timer.cancel();
	}
}